<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 1. 创建XMLHttpRequest对象
        var ajax = new XMLHttpRequest();
        // 2. 设置请求方法和请求地址
        ajax.open('GET', 'https://api.apiopen.top/getJoke?page=1&count=2', true);
        // 3. 设置请求头
        ajax.setRequestHeader('Content-Type', 'application/json');
        // 4. 当请求状态变化时执行的函数
        ajax.onreadystatechange = function () {
            if (ajax.readyState === 4 && ajax.status === 200) {
                // 请求成功，处理响应数据
                var response = JSON.parse(xhr.responseText);
                console.log(response);
            } else if (xhr.readyState === 4 && xhr.status !== 200) {
                // 请求失败，处理错误
                console.error('请求失败，状态码：' + xhr.status);
            }
        }
        ajax.send();
    </script>
</body>

</html>